﻿<?php
$dt_from = '2010-05-05 00:00:00';
$dt_to = '2010-05-05 23:59:59';
	////source datetime convert functions////
	function xl2ts($xl_date){return($xl_date - 25569) * 86400;}//-3600
	function ts2xl($ts_date){return($ts_date + 25569 * 86400)/86400;}//+3600
	
//function xl2ts(&$xl_date){return(($xl_date - 25569)*86400 - 21600);}
//function ts2xl(&$ts_date){return($ts_date + 2209183200)/86400;}

//function dt_converter(&$xl_dt  ){return $xl_dt   = date('Y-m-d H:i:s', xl2ts($xl_dt));}
function dt_converter(&$xl_date){
	$d = new DateTime();
	$d->setTimestamp(xl2ts($xl_date));
	//$d->setTimezone(new DateTimeZone('Asia/Yekaterinburg'));
	$d->sub(new DateInterval('PT'.($d->getOffset()).'S'));

	//return $xl_date = $d->format('Y-m-d H:i:s').'|<span style="color:red">'.($d->getOffset()/3600).'</span>|';
	return $xl_date = $d->format('Y-m-d H:i:s');
}
function d_converter (&$xl_date){
	$d = new DateTime();
	$d->setTimestamp(xl2ts($xl_date));
	//$d->setTimezone(new DateTimeZone('Asia/Yekaterinburg'));
	//$d->add(new DateInterval('PT'.($d->getOffset()-14400).'S'));
	return $xl_date = $d->format('Y-m-d');
}
function t_converter (&$xl_date){
	$d = new DateTime();
	$d->setTimestamp(($xl_date*86400));
	$d->sub(new DateInterval('PT'.($d->getOffset()).'S'));
		$temp = $xl_date*1440;
	return $xl_date = $d->format('H:i:s').'     ['.round($temp).']';
}
function t_MinUp (&$xl_date){
	//$d = new DateTime();
	//$d->setTimestamp(($xl_date*86400));
	//$d->sub(new DateInterval('PT'.($d->getOffset()).'S'));
	return $xl_date = ceil($xl_date*1440);
}
function dur_converter (&$xl_time){return $xl_time = round($xl_time*86400,0);}
function dt_parse    (&$dt){
	$dt_ = DateTime::createFromFormat('Y-m-d H:i:s', $dt);
	//$dt_->setTimezone(new DateTimeZone('Asia/Yekaterinburg'));
	$dt_->add(new DateInterval('PT'.($dt_->getOffset()).'S'));
	return $dt = ts2xl($dt_->getTimeStamp());
}

function callresult (&$t_, &$row_){
	$GLOBALS['stat']['count_all']['c']+=1;
	//$GLOBALS['stat']['dur_all']['c']+=$row_['SUMLENGTH'];
	if($t_!='1'){
		$GLOBALS['stat3']['withoutIVR']+=1;
		if($row_['B1WAITLENGTH']>$GLOBALS['QUALITY'])$GLOBALS['stat3']['bad']+=1;
	}
	switch($t_){
		case '1': 
			$GLOBALS['stat']['count_ivr']['c']+=1;
			break;
		case '2': 
			$GLOBALS['stat']['count_oper']['c']+=1;
			break;
		case '3': 
			$GLOBALS['stat']['count_opers']['c']+=1;
			break;
		case '4': 
			$GLOBALS['stat']['count_agents']['c']+=1;
			//$GLOBALS['stat']['dur_agents']['c']+=$row_['SUMEXTERNALLENGTH'];
			break;
		case '5': 
			$GLOBALS['stat']['count_lost']['c']+=1;
			break;
	}
}

?>